package com.wwj.airline.Controller;

import com.wwj.airline.pojo.Seat;
import com.wwj.airline.Dao.SeatRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/seat")
public class SeatHandler {
    @Autowired(required = false)
    private SeatRepository seatRepository;

    @GetMapping("/findAll")
    public List<Seat> findAll(){
        return seatRepository.findAll();
    }

    @GetMapping("/findById/{id}")
    public Seat findById(@PathVariable("id") Long id){
        return seatRepository.findById(id);
    }

    @GetMapping("/findByFlightId/{flightId}")
    public List<Seat> findByFlightId(@PathVariable("flightId") Long flightId){
        return seatRepository.findByFlightId(flightId);
    }

    @PostMapping("/save")
    public void save(@RequestBody Seat seat){
        seatRepository.save(seat);
    }

    @PutMapping("/update")
    public void update(@RequestBody Seat seat){
        seatRepository.update(seat);
    }

    @PostMapping("/book/{id}")
    public void book(@PathVariable("id") Long id){
        seatRepository.book(id);
    }
    @PostMapping("/sub/{flightId}/{sequence}")
    public void book(@PathVariable("flightId") Long flightId,@PathVariable("sequence") Long sequence){
        seatRepository.sub(flightId,sequence);
    }


    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id){
        seatRepository.deleteById(id);
    }
}
